#include "widget.h"
#include <QApplication>
#include <QSqlDatabase>
#include <QSqlError>
#include <QMessageBox>

bool CreateConn()

{
    //开辟数据库
    QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE", "conn");
    db = QSqlDatabase::addDatabase("QSQLITE");
    db.setDatabaseName("test.db");
    //db.setHostName("host");
    //db.setDatabaseName("dbname");
    //db.setUserName("username");
    //db.setPassword("password");
    if (!db.open())
    {
        QMessageBox::critical(NULL, QObject::tr("Database Error"), db.lastError().text());
        return false;
    }
    return true;
}

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    if (!CreateConn())
        return 1;
    Widget w;
    w.show();

    return a.exec();
}
